package base.render;

import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glColor3f;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import static org.lwjgl.opengl.GL11.glVertex2f;

import org.lwjgl.opengl.GL11;

import base.common.ILiving;
import base.common.IRender;

public abstract class Render implements IRender
{
	public abstract void onRender(ILiving par1ILiving);

	public static void drawBox(float par1, float par2, float par3, float par4)
	{
		glTranslatef(par1, par2, 0);

		glBegin(GL_QUADS);
		{
			glVertex2f(0, 0);
			glVertex2f(0, par4);
			glVertex2f(par3, par4);
			glVertex2f(par3, 0);
		}
		glEnd();
	}

	public static void drawCenteredBox(float par1, float par2, float par3, float par4)
	{
		glTranslatef(par1, par2, 0);

		glBegin(GL_QUADS);
		{
			glVertex2f(-par3 / 2, -par4 / 2);
			glVertex2f(-par3 / 2, par4 / 2);
			glVertex2f(par3 / 2, par4 / 2);
			glVertex2f(par3 / 2, -par4 / 2);
		}
		glEnd();
	}

	public static void drawWithColor(int par1)
	{
		glColor3f(ColorUtil.getRed(par1) / 255F, ColorUtil.getGreen(par1) / 255F, ColorUtil.getBlue(par1) / 255F);
	}

	public static void drawWithRotation(float par1)
	{
		glRotatef(-par1, 0F, 0F, 1F);
	}

	public static void drawCircle(float par1, float par2, float par3, int par4) 
	{
		double theta = (Math.PI * 2) / par4;
		double tanFac = Math.tan(theta);

		double radFac = Math.cos(theta);

		float x = par3;
		float y = 0;

		GL11.glBegin(GL11.GL_LINE_LOOP);
		{
			for (int i = 0; i < par4; i++)
			{
				GL11.glVertex2f(x + par1, y + par2);

				float tanX = -y;
				float tanY = x;

				x += tanX * tanFac;
				y += tanY * tanFac;
				x *= radFac;
				y *= radFac;
			}
		}
		GL11.glEnd();
	}

	public static void drawArc(float par1, float par2, float par3, float par4, float par5, int par6)
	{
		double theta = par5 / (float) (par6 - 1);
		double tanFac = Math.tan(theta);
		double radFac = Math.cos(theta);

		float x = (float) (par3 * Math.cos(par4));
		float y = (float) (par3 * Math.sin(par3));

		GL11.glBegin(GL11.GL_LINE_STRIP);
		{
			for (int i = 0; i < par6; i++)
			{
				GL11.glVertex2f(x + par1, y + par2);

				float tanX = -y;
				float tanY = x;

				x += tanX * tanFac;
				y += tanY * tanFac;

				x *= radFac;
				y *= radFac;
			}
		}
		GL11.glEnd();
	}

	public static void drawFilledCircle(float par1, float par2, float par3, int par4)
	{
		GL11.glTranslatef(par1, par2, 0);
		GL11.glScalef(par3, par3, 1F);

		GL11.glBegin(GL11.GL_TRIANGLE_FAN);
		{
			GL11.glVertex2f(0, 0);
			for(int i = 0; i <= par4; i++)
			{
				double theta = (Math.PI * 2 * i) / par4;
				GL11.glVertex2f((float)Math.cos(theta), (float)Math.sin(theta));
			}
		}
		GL11.glEnd();
	}
}
